<template>
  <!--  截止日期-->
  <div class="date-filter">
    <div class="title">{{ cmpsTitle }}</div>
    <div class="date-change">
      <el-select v-model="filterListData[0].compare" :teleported="false" @change="changeDateType">
        <el-option
          v-for="item in filterListData[0].condition"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        ></el-option>
      </el-select>
      <el-date-picker
        v-if="filterListData[0].compare === 'between'"
        v-model="filterListData[0].value"
        :teleported="false"
        type="daterange"
        value-format="YYYY-MM-DD"
        format="YYYY-MM-DD"
        date-format="YYYY-MM-DD"
        range-separator="-"
        start-placeholder="开始时间"
        end-placeholder="结束时间"
      />
      <el-date-picker
        v-else
        v-model="filterListData[0].value[0]"
        :teleported="false"
        type="date"
        value-format="YYYY-MM-DD"
        format="YYYY-MM-DD"
        date-format="YYYY-MM-DD"
      />
    </div>
    <div class="date-filter__buttons">
      <el-button type="primary" class="buttons-cancel" link size="default" @click="handelReset">重置</el-button>
      <el-button type="primary" class="buttons-confirm" size="default" @click="handelConfirm">确定</el-button>
    </div>
  </div>
</template>

<script setup>
import { ref, watch } from "vue";

const props = defineProps({
  cmpsTitle: {
    type: String,
    default: "开工日期"
  },
  filterList: {
    type: Array,
    default: () => [
      {
        title: "截止日期",
        filterId: "receice_task_plain_end_time",
        condition: [
          {
            label: "时间范围",
            value: "between"
          },
          {
            label: "大于某日",
            value: "gt"
          },
          {
            label: "等于某日",
            value: "eq"
          },
          {
            label: "小于某日",
            value: "le"
          }
        ],
        option: {
          type: "SelectInput",
          lazy: false,
          dataSource: {},
          data: []
        },
        compare: "between",
        value: []
      }
    ]
  }
});
const emit = defineEmits(["handelFilterData"]);
const filterListData = ref([]);

watch(
  () => props.filterList,
  newVal => {
    filterListData.value = [...newVal];
  },
  { deep: true, immediate: true }
);

const handelReset = () => {
  filterListData.value[0].compare = "between";
  filterListData.value[0].value = [];
  emit("handelFilterData", filterListData.value);
};
const handelConfirm = () => {
  emit("handelFilterData", filterListData.value);
};

/**
 * 时间类型
 */
const changeDateType = e => {
  if (e === "between") {
    return (filterListData.value[0].value = []);
  }
  filterListData.value[0].value = [""];
};
</script>

<style scoped lang="scss">
@import "receiceTaskPlainEndTime";
</style>
